from PySide6.QtWidgets import QPushButton, QSizePolicy, QApplication
from PySide6.QtCore import Qt
from PySide6.QtGui import QIcon


class FlatCommandLinkButton(QPushButton):
	def __init__(self, text, icon=None, parent=None):
		super().__init__(parent)
		self.setText(text)
		if icon:
			self.setIcon(QIcon(icon))
		self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
		self.setStyleSheet("""
            QPushButton {
                border: none;
                background-color: transparent;
                padding: 8px 16px;
                margin: 0;
            }
            QPushButton:hover {
                background-color: #e7e7e7;
            }
            QPushButton:pressed {
                background-color: #d7d7d7;
            }
            QPushButton QIcon {
                top: 2px;
                left: 8px;
                width: 16px;
                height: 16px;
            }
            QPushButton QLabel {
                padding-left: 24px;
            }
        """)


if __name__ == "__main__":
	app = QApplication([])
	button = FlatCommandLinkButton("Button", "icon.png")
	button.show()
	app.exec()